{include file="layout/header" /}
    <div class="layui-body">
        <!-- 内容主体区域 -->
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
            <legend>指定允许上传的文件类型</legend>
        </fieldset>

        <button type="button" class="layui-btn" id="test3"><i class="layui-icon"></i>上传文件</button>
        <div class="layui-upload-list">
            <img class="layui-upload-img" id="demo1">
            <p id="demoText"></p>
        </div>
        <!--<p id="demoText"></p>-->
        <button type="button" class="layui-btn layui-btn-primary" id="test4"><i class="layui-icon"></i>只允许压缩文件</button>
        <div class="layui-upload-list">
            <img class="layui-upload-img" id="demo2">
            <p id="demoText1"></p>
        </div>
        <button type="button" class="layui-btn" id="test5"><i class="layui-icon"></i>上传视频</button>
        <button type="button" class="layui-btn" id="test6"><i class="layui-icon"></i>上传音频</button>
        <div style="margin-top: 10px;">

        <!-- 示例-970 -->
        <ins class="adsbygoogle" style="display:inline-block;width:970px;height:90px" data-ad-client="ca-pub-6111334333458862" data-ad-slot="3820120620"></ins>

        </div>
    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        © layui.com - 底部固定区域

    </div>
</div>
<script src="/static/layui/layui.js"></script>
<script>
    //JavaScript代码区域
    layui.use('upload', function(){
        var $ = layui.jquery,upload = layui.upload;
    });
</script>
<script>
    //var upload = layui.upload;
    //指定允许上传的文件类型
    layui.use(['upload','jquery'], function(){
        var upload = layui.upload;
        var jquery = layui.jquery;
        upload.render({
        elem: '#test3'
        ,url: "{:url('index/uploadLayui')}"
        ,auto: true
        ,accept: 'file' //普通文件
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    jquery('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done:function (res,index,upload){
                console.log(res);
                jquery('#file').attr('value',res.data);
            }
        });
        upload.render({ //允许上传的文件后缀
        elem: '#test4'
        ,url: "{:url('index/uploadLayui')}"
        ,accept: 'file' //普通文件
        ,exts: 'zip|rar|7z' //只允许上传压缩文件
        ,auto: true
        ,before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                jquery('#demo2').attr('src', result); //图片链接（base64）
            });
        }
        ,done:function (res,index,upload){
            console.log(res);
            jquery('#file').attr('value',res.data);
        }
        });
        upload.render({
        elem: '#test5'
        ,url: "{:url('index/uploadLayui')}"
        ,accept: 'video' //视频
        ,done: function(res,index,upload){
            console.log(res)
        }
        });
        upload.render({
        elem: '#test6'
        ,url: "{:url('index/uploadLayui')}"
        ,accept: 'audio' //音频
        ,done: function(res,index,upload) {
            console.log(res)
        }
        });
    });
</script>
{include file="layout/footer" /}